﻿using System;
using System.Collections.Generic;

namespace CodeCounsel.SharePoint2010.DigiD
{
    class VerifyWebRequest
        : WebRequest<VerifyWebResponse>
    {
        string _requestID;
        string _userID;
        string _serverID;

        public VerifyWebRequest(string requestID, string userID, string serverID, DigiDSettings settings)
            : base(settings)
        {
            _requestID = requestID;
            _userID = userID;
            _serverID = serverID;
        }

        protected override void GetParameters(Dictionary<string, string> requestParameters)
        {
            requestParameters[Schema.RequestType] = RequestType.Verify;
            requestParameters[Schema.ASelectCredentials] = _userID;
            requestParameters[Schema.RequestID] = _requestID;
            requestParameters[Schema.SharedSecret] = Settings.SharedSecret;
            requestParameters[Schema.ASelectServer] = _serverID;
        }

        protected override VerifyWebResponse CreateResponse(Dictionary<string, string> responseParameters)
        {
            return new VerifyWebResponse(responseParameters);
        }

        protected override void ValidateResponse(VerifyWebResponse response)
        {
            base.ValidateResponse(response);
            if (response.SecurityLevel < Settings.SecurityLevel)
            {
                throw new DigiDException("Client authenticated with too low security level.");
            }
        }
    }
}
